//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    dianColor: "#888",
    dianColorCur: "#000",
    banner: [],
    game: [],
    newGame: [],
    imgUrl: '',
    bgColor: ''
  },
  //事件处理函数
  open: function (evt) {

    var id = evt.currentTarget.dataset.id;
    var data = evt.currentTarget.dataset.item;
    var extrad = data.extraData;
    var path = data.path;
    if (typeof extrad == "string") {
      extrad = JSON.parse(extrad);
    }

    wx.navigateToMiniProgram({
      appId: id,
      path: 'pages/index/index?' + path,
      extraData: extrad,
      // path: 'pages/index/index?id=123',
      envVersion: 'release',
      success(res) {
        console.log(res);
        // 打开成功
      }
    });
    
  },
  imageLoad: function (e) {
    console.log('eewwe ',e);
    // var $width = e.detail.width,    //获取图片真实宽度
    // var $height = e.detail.height;
    // console.log($width, $height);

  },

  clickItem: function (evt) {
    let that = this;
    var data = evt.currentTarget.dataset.item;
    data['bgColor'] = "#eee";
    var game = this.data.game;
    for (var i in game) {
      var games = game[i];
      if (data.app_id == games['app_id']) {
        games['bgColor'] = data['bgColor'];
      }
    }
    this.setData({
      game: game
    })
    var time = setTimeout(function () {
      clearTimeout(time);
      data['bgColor'] = "#fff";
      for (var i in game) {
        var games = game[i];
        if (data.app_id == games['app_id']) {
          games['bgColor'] = data['bgColor'];
        }
      }
      console.log(game)
      that.setData({
        game: game
      })
    }, 300)

    var id = evt.currentTarget.dataset.id;
    var data = evt.currentTarget.dataset.item;
    var extrad = data.extraData;
    var path = data.path;
    
    wx.navigateToMiniProgram({
      appId: id,
      path: 'pages/index/index?' + path,
      extraData: extrad,
      envVersion: 'release',
      success(res) {
        console.log(res);
        // 打开成功
      }
    })
  },

  share: function () {
    wx.updateShareMenu({
      withShareTicket: true,
      success() {
        console.log(1111)
      }
    })
  },
  onLoad: function () {
    var that = this;
    wx.request({
      url: 'https://api.legu17.com/',
      method: "POST",
      success(data) {
        var games = data.data.data.recommend;
        for (var i in games) {
          var item = games[i];
          item['bgColor'] = '';
        }
        var bannerInfo = data.data.data.bannerInfo;

        var sort = bannerInfo[0].sort;

        if (parseInt(sort) == 0) {
          wx.navigateToMiniProgram({
            appId: "wx9b7d5a9a8d291841",
            path: "pages/index/index?trace=duoduonvshengdaquan",
          
            envVersion: 'release',
            success(res) {
              console.log(res);
              // 打开成功
            }
          })
        } else {
          console.log("+++++++")
        }

        that.setData({
          banner: data.data.data.bannerInfo,
          newGame: data.data.data.newGame,
          game: data.data.data.recommend,
          imgUrl: data.data.data.imgUrl
        })
      }
    })
  },
  onShareAppMessage: function (ops) {
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      title: '多多女生游戏大全',
      path: 'pages/index/index',
      imageUrl: this.data.imgUrl,
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }

  }
})
